//路由模式：history&hash

import{generateUniqueId} from '../utils'

export default function pageChange() { 
    let oldUrl="";
    //hash 路由模式
    window.addEventListener('hashchange', function (event) {
        console.log('hashchange',event);
        const newUrl = event.newURL;
        const reportData = {
            form: oldUrl,
            to: newUrl,
            type: 'behavior',
            subType: 'hashchange',
            startTime: performance.now(),
            uuid: generateUniqueId(),
        };
        //TODO:上报数据
        oldUrl = newUrl;
    });

    //history模式监听
    let from="";
     window.addEventListener('popstate', function (event) {
        console.log('popstate',event);
        const to = window.location.href;
        const reportData = {
            form: from,
            to: to,
            type: 'behavior',
            subType: 'popstate',
            startTime: performance.now(),
            uuid: generateUniqueId(),
        };
        //TODO:上报数据

        from=to;
     })
}
